import 'package:flutter/material.dart';

class PageViewFullPage extends StatefulWidget {
  const PageViewFullPage({super.key});

  @override
  State<PageViewFullPage> createState() => _PageViewFullPageState();
}

class _PageViewFullPageState extends State<PageViewFullPage> {
  List<Widget> list = [];
  @override
  void initState() {
    for (var i = 0; i < 5; i++) {
      list.add(Center(
          child: Text(
        '第${i + 1}屏',
        style: const TextStyle(fontSize: 60),
      )));
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        scrollDirection: Axis.vertical,
        onPageChanged: (index) {
          if (index + 2 == list.length) {
            for (var i = 0; i < 5; i++) {
              setState(() {
                list.add(Center(
                    child: Text(
                  '第${i + 1}屏',
                  style: const TextStyle(fontSize: 60),
                )));
              });
            }
          }
        },
        children: list,
      ),
    );
  }
}
